package com.zfzs.post.modules.goods.rest;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.modules.goods.service.GoodsOrderWebService;
import com.zfzs.post.modules.goods.service.dto.GoodOrderQueryCriteria;
import com.zfzs.post.modules.goods.service.dto.HandleOrderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wq
 * @date 2019/11/19 17:17
 * @description
 */
@RestController
@RequestMapping("goods_order")
public class GoodsOrderController {

    @Autowired
    private GoodsOrderWebService goodsOrderWebService;

    @Log("分页查询订单")
    @GetMapping("/list")
    @PreAuthorize("hasAnyRole('ADMIN','POSTTERMINALINFO_ALL','POSTTERMINALINFO_SELECT')")
    public ResponseResult getGoodsOrderPage(GoodOrderQueryCriteria criteria, Integer page, Integer size){
        Map<String, Object> map = goodsOrderWebService.getGoodsOrderPage(criteria, page, size);
        return ResponseResult.ok(map);
    }

    @Log("处理订单")
    @PostMapping("/handle")
    @PreAuthorize("hasAnyRole('ADMIN','POSTTERMINALINFO_ALL','POSTTERMINALINFO_SELECT')")
    public ResponseResult handleOrder(@RequestBody HandleOrderDTO dto){
        goodsOrderWebService.handleOrder(dto);
        return ResponseResult.ok();
    }
    @Log("查询详情")
    @GetMapping("/queryOrderInfo/{orderId}")
    @PreAuthorize("hasAnyRole('ADMIN','POSTTERMINALINFO_ALL','POSTTERMINALINFO_SELECT')")
    public ResponseResult queryOrderInfo(@PathVariable Integer orderId){
        Map<String,Object> map = goodsOrderWebService.queryOrderInfo(orderId);
        return ResponseResult.ok(map);
    }


}
